3 ROS2 Topics

Topic-SinglePublisherandSingleSubscriber.gif
Topic-MultiplePublisherandMultipleSubscriber.gif

  • Open a new terminal (Ctr + Alt + T) and run:
ros2 run turtlesim turtlesim_node
  • Open another terminal (Ctr + Alt + T) and run:
ros2 run turtlesim turtle_teleop_key
  • Open another terminal (Ctr + Alt + T) and run:
rqt_graph

Pasted image 20250929115034.png

  • Running the ros2 topic list command in a new terminal (Ctr + Alt + T) will return a list of all the topics currently active in the system:
ros2 topic list

Pasted image 20250929115254.png

Pasted image 20250929115311.png

  • To see the data being published on a topic, use: ros2 topic echo <topic_name> in a new terminal (Ctr + Alt + T)
ros2 topic echo /turtle1/cmd_vel

Pasted image 20250929115433.png

• Another way to look at this is running in a new terminal (Ctr + Alt + T)

ros2 topic info /turtle1/cmd_vel

ros2 interface show

  • a new terminal (Ctr + Alt + T), run this
ros2 interface show geometry_msgs/msg/Twist
  • This expresses velocity in free space broken into its linear and angular parts.
    Vector3  linear
    Vector3  angular

ros2 topic pub

  • Now that you have the message structure, you can publish data onto a topic directly from the command line using:
ros2 topic pub --once /turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.8}}“

--once is an optional argument meaning “publish one message then exit”.

Pasted image 20250929120004.png

ros2 topic pub --rate 1 /turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.8}}“

The difference here is the removal of the --once option and the addition of the --rate 1 option, which tells ros2 topic pub to publish the command in a steady stream at 1 Hz.

Ros2 topic echo

  • To see the message
ros2 topic echo /turtle1/pose

Pasted image 20250929120122.png

  • To see pub rate
ros2 topic hz /turtle1/pose

average rate: 59.354
min: 0.005s max: 0.027s std dev: 0.00284s window: 58